package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.enums.ResultEnum;
import com.dongdongshop.page.PageResult;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("sel")
public class TbSellerController {

    @DubboReference
    private TbSellerService sellerService;

    private Logger logger = LoggerFactory.getLogger(TbSellerController.class);

    @RequestMapping("show")
    public String show(){
        return "admin/seller_1";
    }
    @RequestMapping("show2")
    public String show2(){
        return "admin/seller";
    }
    @RequestMapping("listSeller")
    @ResponseBody
    public Result listSeller(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "3") Integer pageSize,
                             String name,String sName){
        try {
            PageResult<TbSeller> listSeller = sellerService.selectSeller(name,sName,pageNum,pageSize);
            return Result.OK().setData(listSeller);
        }catch (Exception e){
            logger.info("查询模板出现异常: {}",e);
            return Result.response(ResultEnum.SELECT_MESSAGE_ERROE);
        }
    }
    @RequestMapping("listSeller2")
    @ResponseBody
    public Result listSeller2(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "3") Integer pageSize,
                             String name,String sName,String staus){
        try {
            PageResult<TbSeller> listSeller = sellerService.selectSeller2(name,sName,pageNum,pageSize,staus);
            return Result.OK().setData(listSeller);
        }catch (Exception e){
            logger.info("查询模板出现异常: {}",e);
            return Result.response(ResultEnum.SELECT_MESSAGE_ERROE);
        }
    }
    @RequestMapping("selectById")
    @ResponseBody
    public Result selectById(String id,HttpSession session){
        try {
            session.setAttribute("id",id);

            TbSeller seller = sellerService.selectSellerById(id);
            return Result.OK().setData(seller);
        }catch (Exception e){
            logger.info("查询模板出现异常: {}",e);
            return Result.response(ResultEnum.SELECT_MESSAGE_ERROE);
        }
    }
    @RequestMapping("auditYes")
    @ResponseBody
    public Result auditYes(HttpSession session){
        try {
            String id = (String)session.getAttribute("id");
            TbSeller seller = sellerService.selectSellerById(id);
            seller.setStatus("1");
            sellerService.updateById(seller);
            return Result.response(ResultEnum.AUDIT_MESSAGE_SUCCESS);
        }catch (Exception e){
            logger.info("查询模板出现异常: {}",e);
            return Result.response(ResultEnum.SELECT_MESSAGE_ERROE);
        }
    }
    @RequestMapping("auditNo")
    @ResponseBody
    public Result auditNo(HttpSession session){
        try {
            String id = (String)session.getAttribute("id");
            TbSeller seller = sellerService.selectSellerById(id);
            seller.setStatus("2");
            sellerService.updateById(seller);
            return Result.response(ResultEnum.AUDIT_MESSAGE_ERROER);
        }catch (Exception e){
            logger.info("查询模板出现异常: {}",e);
            return Result.response(ResultEnum.SELECT_MESSAGE_ERROE);
        }
    }
    @RequestMapping("auditKill")
    @ResponseBody
    public Result auditKill(HttpSession session){
        try {
            String id = (String)session.getAttribute("id");
            TbSeller seller = sellerService.selectSellerById(id);
            seller.setStatus("3");
            sellerService.updateById(seller);
            return Result.response(ResultEnum.AUDIT_MESSAGE_KILL);
        }catch (Exception e){
            logger.info("查询模板出现异常: {}",e);
            return Result.response(ResultEnum.SELECT_MESSAGE_ERROE);
        }
    }
}
